<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\YjBanner;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class YjBannerController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid

     */
    protected  $status = [
      1 => "未启用",
      2 => "已启用"
    ];
    protected function grid()
    {

        return Grid::make(new YjBanner(), function (Grid $grid) {
            $grid->id->sortable();
            $grid->img->image("",60,180);
            $grid->notice;
            $grid->status->using($this->status);
            $grid->created_at->sortable();
            $grid->updated_at->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('notice');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new YjBanner(), function (Show $show) {
            $show->id;
            $show->img->image();
            $show->status->using($this->status);
            $show->created_at;
            $show->updated_at;
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new YjBanner(), function (Form $form) {
            $form->display('id');
            $form->image('img')->required();
            $form->text("notice") ;
            $form->select('status')->options($this->status);
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
